package com.shooter.dao;

import com.shooter.utils.PrintUtil;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DbConfig {
    public static String jdbc_url;
    public static String driver_class;
    public static String db_username;
    public static String db_password;
    public static int maxPoolSize;
    public static int minPoolSize;
    public static int maxIdleTime;
    public static int idleConnectionTestPeriod;
    public static int checkoutTimeout;
    public static int acquireIncrement;
    public static int maxStatements;

    static {
        Properties prop = new Properties();
        InputStream in = DbConfig.class.getResourceAsStream("../../../sql_config.properties");
        try {
            prop.load(in);
            jdbc_url = prop.getProperty("jdbc_url").trim();
            driver_class = prop.getProperty("driver_class").trim();
            db_username = prop.getProperty("db_username").trim();
            db_password = prop.getProperty("db_password").trim();
            maxPoolSize = Integer.valueOf(prop.getProperty("maxPoolSize").trim());
            minPoolSize = Integer.valueOf(prop.getProperty("minPoolSize").trim());
            maxIdleTime = Integer.valueOf(prop.getProperty("maxIdleTime").trim());
            idleConnectionTestPeriod = Integer.valueOf(prop.getProperty("idleConnectionTestPeriod").trim());
            checkoutTimeout = Integer.valueOf(prop.getProperty("checkoutTimeout").trim());
            acquireIncrement = Integer.valueOf(prop.getProperty("acquireIncrement").trim());
            maxStatements = Integer.valueOf(prop.getProperty("maxStatements").trim());
        } catch (IOException e) {
            PrintUtil.printError(e);
        }
    }
}
